﻿// <copyright file="WaitCursor.xaml.cs" company="Soumya Chattopadhyay">
// Copyright (c) 2010 All Right Reserved
// </copyright>
// <disclaimer> This software is intented for educational purposes only and not for 
// commerical or prodution use. The software is provided "as is", without warranty 
// of any kind, express or implied, including but not limited to the warranties of 
// merchantability, fitness for a particular purpose and noninfringement. In no event 
// shall the author(s) or copyright holder(s) be liable for any claim, damages or other 
// liability, whether in an action of contract, tort or otherwise, arising from, out of 
// or in connection with the software or the use or other dealings in the software.
// </disclaimer>

namespace My.CodePlex.TFSExplorer
{
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows.Media.Animation;

    /// <summary>
    /// Interaction logic for WaitCursor.xaml
    /// </summary>
    public partial class WaitCursor : UserControl
    {
        #region Fields

        /// <summary>
        /// The storyboard object that controls the animation
        /// </summary>
        private Storyboard storyboard = new Storyboard();

        /// <summary>
        /// The rotate transform property of the target
        /// </summary>
        private RotateTransform rotateTransform = new RotateTransform();

        /// <summary>
        /// The double animation the controls the animation
        /// </summary>
        private DoubleAnimation doubleAnimation = new DoubleAnimation();

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the WaitCursor class
        /// </summary>
        public WaitCursor()
        {
            InitializeComponent();
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Starts the animation of the wait cursor
        /// </summary>
        public void Start()
        {
            this.doubleAnimation.To = 360.0;
            this.doubleAnimation.Duration = new System.Windows.Duration(new TimeSpan(0, 0, 0, 0, 700));
            this.doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

            this.rotateTransform = (RotateTransform)canvas.RenderTransform;
            this.rotateTransform.BeginAnimation(RotateTransform.AngleProperty, this.doubleAnimation);

            this.Visibility = Visibility.Visible;
        }

        /// <summary>
        /// Stops the animation of the wait cursor
        /// </summary>
        public void Stop()
        {
            this.rotateTransform.BeginAnimation(RotateTransform.AngleProperty, null);
            this.Visibility = Visibility.Collapsed;
        }

        #endregion
    }
}
